package tech.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.aistar.dto.AgentGrade;
import tech.aistar.entity.Agent;
import tech.aistar.entity.House;
import tech.aistar.mapper.AgentMapper;
import tech.aistar.service.IAgentService;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: shuaiguo
 * @Date: 2020/09/28/21:05
 * @Description:
 */
@Service
public class AgentServiceImpl implements IAgentService {
    @Autowired
    private AgentMapper agentMapper;
    @Override
    public List<Agent> selectAll() {
        return agentMapper.selectAll();
    }

    @Override
    public List<AgentGrade> selectAgent() {
        return agentMapper.selectAgent();
    }

    @Override
    public List<AgentGrade> selectAgentByName(String name) {
        return agentMapper.selectAgentByName(name);
    }

    @Override
    public void insertAgent(Integer registerId, String identity) {
        agentMapper.insertAgent(registerId,identity);
    }


    @Override
    public PageInfo<AgentGrade> findByPage(String name, Integer pageNow, Integer pageSize) {
        PageHelper.startPage(pageNow,pageSize);

        List<AgentGrade> agentGrades =  selectAgentByName(name);

        PageInfo<AgentGrade> agentPageInfo = new PageInfo<>(agentGrades);

        return agentPageInfo;
    }

    @Override
    public void insert(Agent agent) {
        agentMapper.insert(agent);
    }

    @Override
    public void updateByPrimaryKey(Agent agent) {
        agentMapper.updateByPrimaryKey(agent);
    }

    @Override
    public void deleteByPrimaryKey(Integer id) {
        agentMapper.deleteByPrimaryKey(id);

    }

    @Override
    public Agent selectById(Integer id) {
        return agentMapper.selectById(id);
    }

    @Override
    public int updatephoneById(String phone, Integer id) {
        return agentMapper.updatephoneById(phone,id);
    }

    @Override
    public int updateNameById(String name, Integer id) {
        return agentMapper.updateNameById(name,id);
    }

    @Override
    public int updategenderById(String gender, Integer id) {
        return agentMapper.updategenderById(gender,id);
    }

    @Override
    public int updateIdentityById(String identityCardNumber, Integer id) {
        return agentMapper.updateIdentityById(identityCardNumber,id);
    }

    @Override
    public Agent selectByregisterId(Integer registerId) {
        return agentMapper.selectByregisterId(registerId);
    }

}
